package com.leaf.u_jvm;

/**
 * 虚拟机栈和本地方法栈OOM测试
 * 
 * VM args:-Xss128k
 * 
 * 使用-Xss参数减少栈内存容量。结果：抛出StackOverflowError异常，异常出现时输出的栈深度相应缩小
 * 定义了大量的本地变量，增大此方法帧中本地变量表的长度。结果：抛出StackOverflowError异常时输出的堆栈深度相应缩小
 *
 */
public class JavaVMStackSOF {

	private int stackLength = 1;
	
	public void stackLeak(){
		stackLength ++ ;
		stackLeak();
	}
	
	public static void main(String[] args) throws Throwable {
		JavaVMStackSOF sof = new JavaVMStackSOF();
		try {
			sof.stackLeak();
		} catch (Exception e) {
			throw e;
		} finally {
			System.out.println("stack length:" + sof.stackLength);
		}
	}
}
